<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
题目描述
计算柱子上能接多少雨水
输入
逗号分隔的整数，表示每根柱子的高度。
输出
雨水量（高度和）
样例输入
0,1,0,2,1,0,1,3,2,1,2,1
样例输出
6
https://examacmcoder.oss-accelerate.aliyuncs.com/release/exam/2.1.7/htmls/result/index.html?code=5b26cdc1-240c-44d4-a5f0-9d5401e06282
<script>
    function trap(A) {
        var a = 0;
        var b = A.length - 1;
        var max = 0;
        var leftMax = 0;
        var rightMax = 0;
        while(a < b) {
            leftMax = Math.max(leftMax, A[a]);
            rightMax = Math.max(rightMax, A[b]);
            if(leftMax < rightMax) {
                max += (leftMax - A[a]);
                a++;
            } else {
                max += (rightMax - A[b])
                b--;
            }
        }
        printsth(max);
        return max;
    }
    var input = read_line();
    var arr = input.split(',')
    trap(arr)
</script>
</body>
</html>
